package org.pombo.sqm;

import org.pombo.gtm.Action;
import org.pombo.gtm.Strategy;
import org.pombo.gtm.StrategyNode;

class PlayerNodeWorstPayoffCalculator implements NodeWorstPayoffCalculator<StrategyNode> {

	private StrategyNode node;
	private Strategy strategy;
	private WorstPayoffCalculatorFactory calculate;

	PlayerNodeWorstPayoffCalculator(WorstPayoffCalculatorFactory worstPayoffCalcFactory, Strategy stretegy) {
		this.calculate = worstPayoffCalcFactory;
		this.strategy = stretegy;
	}

	public void setNode(StrategyNode node) {
		this.node = node;
	}

	public double worstPayoff() {
		double worstPayoff = 0;
		for (Action action : this.node.getActions()) {
			worstPayoff += this.strategy.getProbabilityForAction(action)
						* this.calculate.on((this.node.getNodeForAction(action))).worstPayoff();
		}
		return worstPayoff;
	}

}
